package com.the;

import java.util.Map;
import java.util.TreeMap;
import java.util.Comparator;
    public class TreeMapDemo {
       public static void main(String[] args) {
        test02();
       }
       public static void test02() {
        TreeMap<Student, String> treeMap = new TreeMap<>(new Comparator<Student>() {
        @Override
        public int compare(Student o1, Student o2) {
                return o2.getAge() - o1.getAge();
             }
       });

        treeMap.put(new Student("小王", 18), "北京");
        treeMap.put(new Student("小李", 18), "深圳");
        treeMap.put(new Student("小孙", 18), "成都");
        treeMap.put(new Student("小张", 18), "杭州");
        treeMap.forEach((key, value) -> System.out.println(key + ":" + value));
       }

       private static void test01() {
        TreeMap<Student, String> treeMap = new TreeMap<>();

        treeMap.put(new Student("小王", 18), "北京");
        treeMap.put(new Student("小李", 18), "深圳");
        treeMap.put(new Student("小孙", 18), "成都");
        treeMap.put(new Student("小张", 18), "杭州");
        treeMap.forEach((key, value) -> System.out.println(key + ":" + value));


    }
}


